<template>
  <div class="content">
    <my-table
      :data="tableData"
      :col-configs="colConfigs"
      v-loading="listLoading"
      :page-num="pageNum"
      :page-size="pageSize"
      :show-summary="true"
    >
    </my-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
  import {
    getProjectContrac
  } from '@/api/teambalance1'
  import myTable from '@/components/myTable'
  import global from '@/components/global'

  import { AreaSelect } from 'vue-area-linkage'
  import { pca } from 'area-data'
  import { formatDate } from '@/utils/index'

  const billTime = {
    props: ['colConfig'],
    filters: {
      formatDate(time) {
        var date = new Date(time)
        return formatDate(date, 'yyyy-MM-dd')
      }
    },
    template: `
  <el-table-column :label="colConfig.label" :width="colConfig.width">
      <span slot-scope="scope">
        {{ scope.row[colConfig.prop] | formatDate }}
      </span>
  </el-table-column>
  `
  }

  const receivingUnit = function(row, column) {
    if (row.receivingUnit) {
      let obj = {}
      obj = global.billUnitList.find((item) => {
        return item.value === row.receivingUnit // 筛选出匹配数据
      })
      return obj.label
    }
  }

  const stage = function(row, column) {
    if (row.stage) {
      let obj = {}
      obj = global.stageList.find((item) => {
        return item.value === row.stage // 筛选出匹配数据
      })
      return obj.label
    }
  }

  export default {
    components: {
      myTable,
      AreaSelect
    },
    props: ['viewDetailList'],
    data() {
      return {
        colConfigs: [
          { prop: 'projectName', label: '合同项目名称', width: '150', fixed: true },
          { prop: 'billAmount', label: '收款金额(万元)', width: '100', fixed: true },
          { prop: 'actualPay', label: '实到金额(万元)', width: '100', fixed: true },
          { prop: 'teamName', label: '所属团队', width: '150' },
          { prop: 'contractCode', label: '合同编号', width: '150' },
          { prop: 'contractAmount', label: '合同金额(万元)', width: '150' },
          { prop: 'balancePayment', label: '项目尾款(万元)', width: '150' },
          { prop: 'balancePay', label: '本次尾款(万元)', width: '150' },
          { prop: 'partyA', label: '业主', width: '150' },
          { prop: 'address', label: '项目所属地', width: '150' },
          { prop: 'managementCost', label: '管理费(万元)', width: '100' },
          { prop: 'signatureCost', label: '签字费(万元)', width: '100' },
          { prop: 'auditCost', label: '审核费(万元)', width: '100' },
          { prop: 'otherCost', label: '其他费用(万元)', width: '100' },
          { prop: 'billTime', label: '收款时间', width: '150', component: billTime },
          { prop: 'receivingUnit', label: '收款单位', width: '150', formatter: receivingUnit },
          { prop: 'stage', label: '收款阶段', width: '150', formatter: stage }
        ],
        listLoading: true,
        dialogType: 0,
        tableData: [],
        pageNum: 1,
        pageSize: 10,
        total: 1,
        pca: pca,
        rules: {},
        visible: false
      }
    },
    created() {
    },
    computed: {
      global() {
        return global
      },
      teamId() {
        return this.$store.state.user.teamId
      },
      roleType() {
        return this.$store.state.user.roleType
      }
    },
    methods: {
      fetchData() {
        this.viewDetailList.pageNum = this.pageNum
        this.viewDetailList.pageSize = this.pageSize
        this.listLoading = true
        getProjectContrac(this.viewDetailList).then(response => {
          this.tableData = response.responseBody.list
          this.total = response.responseBody.total
          this.listLoading = false
        })
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.pageNum = val
        this.fetchData()
      }
    },
    watch: {
      'viewDetailList': {
        handler(newValue, oldValue) {
          this.fetchData()
        },
        immediate: true
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .content {
    padding: 20px;
  }
</style>


<style rel="stylesheet/scss" lang="scss">
  .el-input__icon {
    line-height: 100%;
  }

  .el-form-item__content {
    line-height: 33px;
  }

  .area-select .area-selected-trigger {
    padding: 0 10px;
  }

  /*.el-table__body tr.hover-row>td {
    background-color: #0000ff !important;
  }

  .el-table__body tr.current-row>td {
    background-color: #0000ff !important;
  }*/
</style>
